package com.leokok.jts.learning.jts.core.algorithm;


import org.junit.Test;
import org.locationtech.jts.algorithm.Intersection;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 判断相交
 */
public class IntersectionTest {


    /**
     * 计算两条线段是否相交,如果平行或者共线返回null
     */
    @Test
    public void intersection() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry l1 = wktReader.read("LINESTRING (115.9265 31.9891, 115.9283 31.9891)");
        Geometry l2 = wktReader.read("LINESTRING (115.92649625 31.98893125, 115.92713875 31.98904)");

        Coordinate coordinate = Intersection.intersection(l1.getCoordinates()[0],l1.getCoordinates()[1],l2.getCoordinates()[0],l2.getCoordinates()[1]);
        System.out.println(coordinate);

    }
}
